import 'package:concierge/app/models/phone_cc.dart';
import 'package:concierge/app/req/provider/CenterApiProvider.dart';
import 'package:concierge/app/req/provider/LifeApiProvider.dart';
import 'package:get/get.dart';

class CommonApi {
  final LifeApiProvider lifeProvider;
  final CenterApiProvider centerProvider;
  CommonApi._(this.lifeProvider, this.centerProvider);
  static CommonApi? _instance;
  static CommonApi get instance {
    _instance ??= CommonApi._(
      Get.find<LifeApiProvider>(),
      Get.find<CenterApiProvider>(),
    );
    return _instance!;
  }

  Future<PhoneCc?> getCountryCode() async {
    var res = await centerProvider.get_(
      "service/cc",
      decoder: PhoneCc.fromJson,
    );
    return res.body;
  }

  Future<bool> sendSmsCode({
    required int cc,
    required String phone_number,
  }) async {
    var res = await lifeProvider.post_("code/$phone_number?cc=$cc", {});
    return res.statusCode == 201;
  }

  Future<bool> sendEmail({required String email}) async {
    var res = await lifeProvider.post_(
      "email/send",
      FormData({"email": email}),
    );
    return res.statusCode == 201;
  }
}
